var rootPath = getRootPath();	
var loveModelNum = 0;
var isExistRoutes = 0;

//加载心仪车型
function initLoveMode(){
	//加载心仪车型
	$.ajax({
        type:"GET", 
        url:rootPath+"/wechat/api/loveModel", 
        dataType:"json",      
        async: false,
        contentType:"application/json",               
        data:null, 
        success:function(data){ 
        	
        	if(data==undefined || data=='' || data.length==0){
        		$("#noLoveModelDiv").show();
        		$("#existLoveModeDiv").hide();
        	}else{
        		$("#noLoveModelDiv").hide();
        		$("#existLoveModeDiv").show();
                // 编辑轮播信息数据
    			var wholeHtml = '';
    			// 轮播（Carousel）指标
    			var carousel_indicatorsHtml = '<ol class="carousel-indicators">';
    			
    			// 轮播（Carousel）项目
    			var carousel_innerHtml = '<div class="carousel-inner">';
    			
    			var indexTemp= 0;
    			$.each(data,function(carModelIndex,carModelObj){
    				indexTemp = carModelIndex;
    				if (0 == carModelIndex){
    					
//    				    carousel_indicatorsHtml+= '<li data-target="#myCarInfos" data-slide-to='+carModelIndex+' class="active"></li>';
    					carousel_indicatorsHtml += '<li class="active"><a href="#" class="active" packageCode='+carModelObj.packageCode+' onclick=setPackageCode(this)><img alt="" src="'+rootPath+'/images/'+carModelObj.brandName+'/外观/'+carModelObj.seriesName+'/'+carModelObj.seriesName+'.jpg'+'"  data-target="#myCarInfos" data-slide-to="'+ carModelIndex +'" class="img-responsive"/ ></a></li>';
    				    carousel_innerHtml += "<div class='item active'>";
    				    //品牌CODE赋值
    				    $("#defaultPackageCode").val(carModelObj.packageCode);
    				} else {
//    					carousel_indicatorsHtml+= '<li data-target="#myCarInfos" data-slide-to='+carModelIndex+' ></li>';
    					carousel_indicatorsHtml += '<li><a href="#" packageCode='+carModelObj.packageCode+' onclick=setPackageCode(this)><img alt="" src="'+rootPath+'/images/'+carModelObj.brandName+'/外观/'+carModelObj.seriesName+'/'+carModelObj.seriesName+'.jpg'+'"  data-target="#myCarInfos" data-slide-to="'+carModelIndex+'" class="img-responsive"/ ></a></li>';
    					carousel_innerHtml += "<div class='item'>";
    				}
    				var localPrice = carModelObj.localPrice;
    				var guidePrice = carModelObj.guidePrice;
    				if(localPrice==undefined || localPrice==''){
    					localPrice = '';
    				}else{
    					localPrice = localPrice.toFixed(2);
    				}
    				if(guidePrice==undefined || guidePrice==''){
    					guidePrice = '';
    				}else{
    					guidePrice = guidePrice.toFixed(2);
    				}
    				
    				carousel_innerHtml += '<table style="width: 99%">';
    				carousel_innerHtml += '  <tr>';
    				carousel_innerHtml += "      <td width='25%' align='left' valign='middle'>";
//    				carousel_innerHtml += "          <div class=''>";
    				carousel_innerHtml += "           <h6  style='font: bolder;color: #000'>"+carModelObj.packageName+"</h6>";
//    				carousel_innerHtml += "           <h6><span class='text-muted'>"+carModelObj.seriesName+"</span></h6>";
//    				carousel_innerHtml += "          </div>";
    				carousel_innerHtml += "       </td>";
    				carousel_innerHtml += '      <td width="35%" align="center"><img src="'+rootPath+'/images/'+carModelObj.brandName+'/外观/'+carModelObj.seriesName+'/'+carModelObj.seriesName+'.jpg'+'" width="150" height="70"></td>';
    				carousel_innerHtml += '      <td width="45%" align="left"><h6><span>指导价：</span><span>'+guidePrice+'</span>万</h6> <p><h6><font color="red"><span>本店价：</span><span>'+localPrice+'</span>万<font></h6></p></td>';
    				carousel_innerHtml += "  </tr>";
    				carousel_innerHtml += "</table>";
    				carousel_innerHtml += "<input type='hidden' id = 'packageCode_"+carModelIndex+"' value='"+carModelObj.packageCode+"' /></div>";
    			});
    			
    			loveModelNum = parseInt(indexTemp)+1;
    			carousel_innerHtml += "<div class='item'>";
				carousel_innerHtml += '<table style="width: 99%">';
				carousel_innerHtml += '  <tr>';
				carousel_innerHtml += "      <td width='25%' align='left' valign='middle'>";
//				carousel_innerHtml += "          <div class=''>";
				carousel_innerHtml += "           <h6  style='font: bolder;color: #000'><a href='#' class='selectBrandSeries''><span class='packageNameSpan'>请选择心仪车型</span><span class='glyphicon glyphicon-chevron-right'></span></a></h6>";
//				carousel_innerHtml += "           <h6><span class='text-muted'>"+carModelObj.seriesName+"</span></h6>";
//				carousel_innerHtml += "          </div>";
				carousel_innerHtml += "       </td>";
				carousel_innerHtml += '      <td width="35%" align="center"><img id="seriesImageAt" src="'+rootPath+'/images/allCar.png'+'" width="150" height="70"></td>';
				carousel_innerHtml += '      <td width="45%" align="center"><h6><span>指导价：</span><span class="guidePriceAt"></span></h6> <p><h6><font color="red"><span>本店价：</span><span class="localPriceAt"></span><font></h6></p></td>';
				carousel_innerHtml += "  </tr>";
				carousel_innerHtml += "</table>";
				
//    			carousel_innerHtml += "<div class='item'>";
//    			carousel_innerHtml += "   <table><tr><td align='right' width='40%'><a href='#'>";
//    			carousel_innerHtml += '<img id="seriesImageAt" src="'+rootPath+'/images/allCar.png'+'" width="150" height="70">';
//    			carousel_innerHtml +="</a></td><td width='10%'><td align='left'><div class=''>";
//    			carousel_innerHtml += "<p>";
//    			carousel_innerHtml +="<h6  style='font: bolder;color: #000'><a href='#' class='selectBrandSeries''><span class='packageNameSpan'>请选择心仪车型</span><span class='glyphicon glyphicon-chevron-right'></span></a></h6>";
//    			carousel_innerHtml +="<p><h6><span>指导价：</span><span class='guidePriceAt'></span></h6></p>";
//    			carousel_innerHtml +="<p><h6><font color='red'><span>本店价：</span><span class='localPriceAt'></span></font></h6></p>";
//    			carousel_innerHtml +="</div></td></tr>";
//    			carousel_innerHtml +="    </table>";
//    			carousel_innerHtml +="</div>";
    			
    			
    			
    			carousel_indicatorsHtml += "</ol> ";
    			carousel_innerHtml += "</div>";
    			
    			// 轮播（Carousel）导航
//    			var carousel_controlHtml = '<a class="carousel-control left"  href="#myCarInfos"  data-slide="prev" type = "button">&lsaquo;</a>';
//    			    carousel_controlHtml += '<a class="carousel-control right" href="#myCarInfos"  data-slide="next" type = "button">&rsaquo;</a>';
//    			
    			$("#myCarInfos").append(carousel_indicatorsHtml);
    			$("#myCarInfos").append(carousel_innerHtml);
        		
        	}
        },
        error:function(data){
        }
     });

}



$(document).ready(function(){
	
	var packageCode = getQueryParamValue("packageCode");
	if(packageCode!=undefined && packageCode!=''){
 		$("#noLoveModelDiv").show();
		$("#existLoveModeDiv").hide();

		$.ajax({
			method : 'get',
			url : rootPath+'/wechat/api/showroom/packages?packageCode='+packageCode,
			error:function(XMLHttpRequest, ajaxOptions, thrownError){
				alert("连接服务器错误!");
			},
			success : function(resultData){
				$("#seriesImageAt").attr("src",rootPath+'/images/'+resultData.brandName+'/外观/'+resultData.seriesName+'/'+resultData.seriesName+'.jpg');
				$("#seriesImageAtNoLoveModel").attr("src",rootPath+'/images/'+resultData.brandName+'/外观/'+resultData.seriesName+'/'+resultData.seriesName+'.jpg');
				$("#defaultBrandName").val(resultData.brandName)
				$("#defaultSeriesName").val(resultData.seriesName)
		        $("#defaultBrandCode").val(resultData.brandCode);
		        $("#defaultSeriesCode").val(resultData.seriesCode);
		        $("#defaultModelCode").val(resultData.modelCode);
		        $("#defaultPackageCode").val(resultData.packageCode);
	 			var guidePriceTemp = resultData.guidePrice;
	 			if(guidePriceTemp!=undefined && guidePriceTemp!=''){
		 			$(".guidePriceAt").html(guidePriceTemp+"万");
	 			}
	 			var localPriceTemp = resultData.localPrice;
	 			if(localPriceTemp!=undefined && localPriceTemp!=''){
		 			$(".localPriceAt").html(localPriceTemp+"万");
	 			}
				$(".packageNameSpan").html(resultData.packageName);
			}
		});
	}else{
		initLoveMode();
	}

	
	//选择试驾路线
	$("#selectTestDriveRoadline").click(function(){
		if(isExistRoutes==0){
			$('#pleaseWhRouteTop').modal({
				keyboard: false,
				backdrop:false
			});
		}else{
		     $("#selectTestDriveRoadlineDiv").addClass("active in");
		     $("#testDriveAppointmentForm").removeClass("active in");
		}
		
	});
	
	//刷新时清空路线
 	$("#defaultRouteNameSpan").html('选择试驾路线');
 	
	
	// 停止自动轮播
	$('#myCarInfos').carousel({
		interval: false
	})
	// 停止自动轮播
	$("#myCarInfos").carousel('pause');
	
	
	$('#myCarInfos').hammer().on('swipeleft', function(){
		$(this).carousel('next');
	});
	
	$('#myCarInfos').hammer().on('swiperight', function(){
		$(this).carousel('prev');
	});

	
	
    $('#myCarInfos').on('slid.bs.carousel', function (e) {
	   	 var active = $(e.target).find('.carousel-inner > .item.active');
	   	 var ccindex = active.index();
	   	 if(ccindex == loveModelNum){
		   	 $("#defaultPackageCode").val($("#defaultPackageCode_ex").val());

	   	 }else{
		   	 $("#defaultPackageCode").val($("#packageCode_"+ccindex).val());
	   	 }
    });
    
    
    
    //加载试驾路线
    
	$.ajax({
        type:"GET", 
		url : rootPath+'/wechat/api/testdrivingAppointment/routes',
        dataType:"json",      
        async: false,
        contentType:"application/json",               
        data:null, 
        success:function(data){ 
        	if(data==undefined || data=='' || data.length==0){
        		isExistRoutes = 0;
//				$('#pleaseWhRouteTop').modal({
//					keyboard: false,
//					backdrop:false
//				});
        	}else{
        		isExistRoutes = 1;
                // 编辑轮播信息数据
    			var wholeHtml = '';
    			// 轮播（Carousel）指标
    			var carousel_indicatorsHtml = '<ol class="carousel-indicators" >';
    			
    			// 轮播（Carousel）项目
    			var carousel_innerHtml = '<div class="carousel-inner"  style="margin-top: 50px;">';
    			
    			var indexTemp= 0;
    			$.each(data,function(carModelIndex,carModelObj){
    				indexTemp = carModelIndex;
    				if (0 == carModelIndex){
    					
    					carousel_indicatorsHtml += '<li class="active"><a href="#" class="active" routeName='+carModelObj.routeName+' routeCode='+carModelObj.routeCode+' onclick=setRouteCode(this)><img alt="" src="'+carModelObj.routeSrc+'"  data-target="#testDriveRoadlineInfoDiv" data-slide-to="'+ carModelIndex +'" class="img-responsive"/ ></a></li>';
    				    carousel_innerHtml += "<div class='item active'>";
    				    //品牌CODE赋值
    				    $("#defaultRouteCode").val(carModelObj.routeCode);
    				    $("#defaultRouteName").val(carModelObj.routeName);
    				} else {
    					carousel_indicatorsHtml += '<li><a href="#" routeCode='+carModelObj.routeName+' onclick=setRouteCode(this)><img alt="" src="'+carModelObj.routeSrc+'"  data-target="#testDriveRoadlineInfoDiv" data-slide-to="'+carModelIndex+'" class="img-responsive"/ ></a></li>';
    					carousel_innerHtml += "<div class='item'>";
    				}
    				
    				
    				carousel_innerHtml += '<table align="center">';
    				carousel_innerHtml += '  <tr align="center">';
    				carousel_innerHtml += '    <td>'+carModelObj.routeName+'</td>';
    				carousel_innerHtml += '  </tr>';
    				carousel_innerHtml += '  <tr height="30px">';
    				carousel_innerHtml += '  </tr>';
    				carousel_innerHtml += '  <tr>';
    				carousel_innerHtml += '      <td><img src="'+carModelObj.routeSrc+'" class="img-responsive"></td>';
    				carousel_innerHtml += "  </tr>";
    				carousel_innerHtml += "</table>";
    				carousel_innerHtml += "<input type='hidden' id = 'routeCode"+carModelIndex+"' routeName='"+carModelObj.routeName+"' value='"+carModelObj.routeCode+"' /></div>";
    			});
    			
    			
    			carousel_indicatorsHtml += "</ol>";
    			carousel_innerHtml += "</div>";
    			
    			// 轮播（Carousel）导航
//    			var carousel_controlHtml = '<a class="carousel-control left"  href="#myCarInfos"  data-slide="prev" type = "button">&lsaquo;</a>';
//    			    carousel_controlHtml += '<a class="carousel-control right" href="#myCarInfos"  data-slide="next" type = "button">&rsaquo;</a>';
//    			
    			$("#testDriveRoadlineInfoDiv").append(carousel_indicatorsHtml);
    			$("#testDriveRoadlineInfoDiv").append(carousel_innerHtml);
        		
        	}
        },
        error:function(data){
        }
     });
	
	// 停止自动轮播
	$('#testDriveRoadlineInfoDiv').carousel({
		interval: false
	})
	// 停止自动轮播
	$("#testDriveRoadlineInfoDiv").carousel('pause');
	
	
	$('#testDriveRoadlineInfoDiv').hammer().on('swipeleft', function(){
		$(this).carousel('next');
	});
	
	$('#testDriveRoadlineInfoDiv').hammer().on('swiperight', function(){
		$(this).carousel('prev');
	});

	
	
    $('#testDriveRoadlineInfoDiv').on('slid.bs.carousel', function (e) {
	   	 var active = $(e.target).find('.carousel-inner > .item.active');
	   	 var ccindex = active.index();
	   	  $("#defaultRouteCode").val($("#routeCode"+ccindex).val());
	   	  $("#defaultRouteName").val($("#routeCode"+ccindex).attr("routeName"));

    });
    
    
    //选择路线确认
    $("#selectTestDriveRoadlineSure").click(function(){
	     $("#selectTestDriveRoadlineDiv").removeClass("active in");
	     $("#testDriveAppointmentForm").addClass("active in");
	     $("#defaultRouteNameSpan").html($("#defaultRouteName").val());
	     $("#defaultRouteCodeSubmit").val($("#defaultRouteCode").val())
    	
    });


	
	//加载服务顾问
	$.ajax({
        type:"GET", 
        url:rootPath+"/wechat/api/potentialUsers/counselor/selectCounselor?positionId=601", 
        dataType:"json",      
        async: false,
        contentType:"application/json",               
        data:null, 
        success:function(data){ 
			var options = [];
			options.push('<option userName="" phone="" value="0">请选择您的销售顾问</option>');
			$.each(data,function(carModelIndex,advisersObj){
				options.push("<option userName='"+advisersObj.userName+"' phone='"+advisersObj.phone+"' value='"+advisersObj.userId  +"'>"+advisersObj.userName+"</option>");
			});
			
			$("#salesConsultantId").append(options.join(""));
        },
        error:function(data){
        	alert("数据刷新失败，请联系管理员！");
        }
     });

	
	 var now = new Date();
	 var currYear = now.getFullYear();	
	 //选择日期时间
     $('#startDate').mobiscroll().datetime({
         theme: 'ios',
         lang: 'zh',
         display: 'bottom',
         mode: 'datetimeInvalid',
         min: new Date(now.getFullYear(), now.getMonth(), now.getDate()),
         invalid: ['w0', 'w6', '5/1', '12/24', '12/25'],
         dateOrder: 'Mddyy',
         timeWheels: 'HHii',
         startYear: currYear,
         dateFormat:'yyyy-mm-dd'
     
     });
	 
	 
	 //立即预约
	 $("#immediatelyAppoint").click(function(){
		 		 
		 var defaultPackageCodeTemp=$("#defaultPackageCode").val();
		 if(defaultPackageCodeTemp==undefined || defaultPackageCodeTemp==''){
				$('#selectLoveModelTop').modal({
					keyboard: false,
					backdrop:false
				});
			return;
		 }
		 
		 
	   	 $('#testDriveAppointmentForm').bootstrapValidator('validate');
	     var isValid=$("#testDriveAppointmentForm").data("bootstrapValidator").isValid();

	     if(!isValid){
	     	return;
	     }
	     
		 var defaultRouteCodeSubmit = $("#defaultRouteCodeSubmit").val();
		 if(defaultRouteCodeSubmit==undefined || defaultRouteCodeSubmit==''){
				$('#selectRouteTop').modal({
					keyboard: false,
					backdrop:false
				});
			return;
		 }
		 
	    var data={
	    	personalName:"",
	    	phone:"",
	    	dealerCode:"",
	    	packageCode:"",
	    	packageName:"",
	    	salesConsultantId:"",
	    	startDate:"",
	    	appointmentContent:"",
	    	routeCode:"",
	    	salesConsultantName:"",
	    	salesConsultantPhone:""
	    }; 
	    
	    data.personalName = $.trim($("#personalName").val()); 
	    data.phone = $.trim($("#phone").val()); 
	    data.packageCode = $.trim($("#defaultPackageCode").val()); 
	    data.packageName = $.trim($("#defaultPackageName").val()); 
	    data.salesConsultantId = $.trim($("#salesConsultantId").val()); 
	    data.startDate = $.trim($("#startDate").val()); 
	    data.appointmentContent = $.trim($("#appointmentContent").val()); 
	    data.routeCode = $.trim($("#defaultRouteCodeSubmit").val());
	    $('#personalNameModal').html(data.personalName);
	    
		var salesConsultantPhone = $("#salesConsultantId").find("option:selected").attr("phone");
		var salesConsultantName = $("#salesConsultantId").find("option:selected").attr("userName");
		 
		if(salesConsultantPhone!=undefined && salesConsultantPhone!=''){
			data.salesConsultantPhone = salesConsultantPhone;
		}
		if(salesConsultantName!=undefined && salesConsultantName!=''){
			data.salesConsultantName = salesConsultantName;
		}
	    
		$.ajax({
			type : 'POST',
			url : rootPath+'/wechat/api/testdrivingAppointment',
			contentType:"application/json",
			data: JSON.stringify(data),
			error:function(XMLHttpRequest, ajaxOptions, thrownError){
				
			},
			success : function(data){
				$('#testdrivingAmModal').modal({
					keyboard: false,
					backdrop:false
				});
			}
				
		});
		
	    
//	 	$.ajax({
//	 		type : 'post',
//			url : rootPath+'/wechat/api/testdrivingAppointment',
//			dataType:'json',
//			async: false,
//	        contentType:"application/json", 
//	        data: {},
//			error:function(XMLHttpRequest, ajaxOptions, thrownError){
//				alert("连接服务器错误!");
//			},
//			success : function(resultData){
//			     
//			}
//			
//			
//		});
	     
	     
	     
	     
		 
	 });
	 
	 $('#selectLoveModelTopSure').click(function(){
     
	 	$('#selectLoveModelTop').modal('hide');
     
	 });	
	 
	 $('#selectRouteTopSure').click(function(){
	     
		 	$('#selectRouteTop').modal('hide');
	     
	 });	
	 $('#pleaseWhRouteTopSure').click(function(){
	     
		 	$('#pleaseWhRouteTop').modal('hide');
	     
	 });	
		
	 //模态框确认
	 $('#modalSure').click(function(){
	     var packageCode = $("#defaultPackageCode").val();
     
	 	$('#testdrivingAmModal').modal('hide');
	     $("#personalName").val(''); 
	     $("#phone").val(''); 
	     $("#defaultPackageCode").val(''); 
	     $("#salesConsultantId").val(''); 
	     $("#startDate").val(''); 
	     $("#appointmentContent").val(''); 
	     $('#testDriveAppointmentForm').data('bootstrapValidator').resetForm(true);
	 	window.location.href = rootPath +"/views/newCarShowroom/packageExhibition.html?packageCode="+packageCode;
	 });	

	 
	 
     $("#testDriveAppointmentForm").addClass("active in");
     $("#carModelExhibitionDiv").removeClass("active in");
	 $("#carModelExhibitionDetailDiv").removeClass("active in");

     //选择品牌车系
     $(".selectBrandSeries").click(function(){
    	 
         var seriesCode = $("#defaultSeriesCode").val();
         
         //判断是否已经已有已选择的车系，车型，配置,如果存在直接进入车型配置选择页面，否则 进入品牌车系选择界面 
     	 if(seriesCode ==undefined || seriesCode==''){
     		 initBrandSeries();
         }else{
        	 initModelPackage(seriesCode);
         }
         
     });
     
     
     //从新选择品牌车系
     $(".againSelectBrandSeries").click(function(){
 		 initBrandSeries();
     });
 });


//初始化加载品牌车系界面 
function initBrandSeries(){
	
	var brandCode = $("#defaultBrandCode").val();
	if(brandCode ==undefined || brandCode==''){
		brandCode='';
	}
	$("#carModelExhibitionDiv").empty();
	
	$.ajax({
		method : 'get',
		url : rootPath+'/wechat/api/showroom/brands?brandCode='+brandCode,
		error:function(XMLHttpRequest, ajaxOptions, thrownError){
			alert("连接服务器错误!");
		},
		success : function(resultData){
			var wholeHtml = '';
			var brandHtml = '';
			var seriesHtml = '';
			
			$.each(resultData,function(brandIndex,brandObj){
				brandHtml = '<h4>'+brandObj.brandName+'</h4>';
				brandHtml +='<ul class="list-group">';
				$.each(brandObj.series,function(seriesIndex,seriesObj){		
					seriesHtml = '<a onclick="selectModelPackage(this)" seriesCode="'+seriesObj.seriesCode+'" href="#" class="list-group-item">'+
								  '<span class="glyphicon glyphicon-chevron-right form-control-feedback"></span>'+
								  seriesObj.seriesName+
	                              '</a>';
					brandHtml +=seriesHtml;
				});
				
				brandHtml +='</ul>';
				
				wholeHtml +=brandHtml;
			});
			
	    	 $("#carModelExhibitionDiv").append(wholeHtml);
		     $("#testDriveAppointmentForm").removeClass("active in");
		     $("#carModelExhibitionDetailDiv").removeClass("active in");
		     $("#carModelExhibitionDiv").addClass("active in");
		     
		}
		
		
	});

}


//初始化加载车型配置页面
function initModelPackage(seriesCode){
	
	$("#carModelPackageExhibitionDiv").empty();
	$.ajax({
		method : 'get',
		url : rootPath+'/wechat/api/showroom/series?seriesCode='+seriesCode,
		error:function(XMLHttpRequest, ajaxOptions, thrownError){
			alert("连接服务器错误!");
		},
		success : function(resultData){
			if(resultData!=undefined && resultData!=''){
				$("#modelNameSpan").html(resultData.seriesName);
				$("#defaultBrandName").val(resultData.brandName)
				$("#defaultSeriesName").val(resultData.seriesName)

			}

			var wholeHtml = '';
			$.each(resultData.models,function(modelIndex,modelObj){
				
				var modelHtml =  '<ul class="list-group">'
							+'    <a href="#" class="list-group-item active">'
							+         modelObj.modelName
					        +'    </a>';
				
				$.each(modelObj.packages,function(packageIndex,packageObj){
					var packageHtml = '<a href="#" onclick="selectConcretePackage(this)" guidePrice='+packageObj.guidePrice+' localPrice='+packageObj.localPrice+' modelCode='+modelObj.modelCode+' packageCode='+packageObj.packageCode+' packageName='+packageObj.packageName+' class="list-group-item">'
							  	 +'  <span class="glyphicon glyphicon glyphicon-heart form-control-feedback"></span>'
							  	 +       packageObj.packageName
					             +'</a>';
					
					 
					modelHtml +=packageHtml;
					
				});
				
				modelHtml +='</ul>';
				
				wholeHtml +=modelHtml;
				
			});
			
			 $("#carModelPackageExhibitionDiv").append(wholeHtml);
		     $("#testDriveAppointmentForm").removeClass("active in");
		     $("#carModelExhibitionDiv").removeClass("active in");
			 $("#carModelExhibitionDetailDiv").addClass("active in");
			
		}
	});

}
 
 
 
 //选择车型配置页面
 function selectModelPackage(obj){
	 var seriesCode = $(obj).attr("seriesCode");
	 
	 $("#defaultSeriesCode").val(seriesCode);
	 initModelPackage(seriesCode);
 }
 
 
 //选择具体的车型配置
 function selectConcretePackage(obj){
	 var modelCode = $(obj).attr("modelCode");
	 var packageCode = $(obj).attr("packageCode");
//	 var packageName = $(obj).attr("packageName");
	 var guidePriceTemp = $(obj).attr("guidePrice");
	 var localPriceTemp = $(obj).attr("localPrice");
	 
	 if(guidePriceTemp!=undefined && guidePriceTemp!=''){
	 	$(".guidePriceAt").html(guidePriceTemp+"万");
	 }
	 
	 if(localPriceTemp!=undefined && localPriceTemp!=''){
	 	$(".localPriceAt").html(localPriceTemp+"万");
	 }
	 
	 var packageName = $(obj).text();
	 	 
	 $(".packageNameSpan").html(packageName);
	 
	 $("#defaultModelCode").val(modelCode);
	 $("#defaultPackageCode").val(packageCode);
	 $("#defaultPackageCode_ex").val(packageCode); 	 
	 var brandName =$("#defaultBrandName").val();
	 var seriesName =$("#defaultSeriesName").val();
	 $("#seriesImageAt").attr("src",rootPath+'/images/'+brandName+'/外观/'+seriesName+'/'+seriesName+'.jpg');
	 $("#seriesImageAtNoLoveModel").attr("src",rootPath+'/images/'+brandName+'/外观/'+seriesName+'/'+seriesName+'.jpg');
     
	 $("#carModelExhibitionDiv").removeClass("active in");
	 $("#carModelExhibitionDetailDiv").removeClass("active in");
     $("#testDriveAppointmentForm").addClass("active in");
 }
 
 function setPackageCode(obj){
	 var packageCode = $(obj).attr("packageCode");
	 $("#defaultPackageCode").val(packageCode);
 }
 
 function setRouteCode(obj){
	 var routeCode = $(obj).attr("routeCode");
	 var routeName = $(obj).attr("routeName");
	 $("#defaultRouteCode").val(routeCode);
	 $("#defaultRouteName").val(routeName);
 }
 

 
 
